package Matrix;

import SeqList.SeqList;

public class MartixGraph<E extends Comparable<E>> {
    private SeqList<E> seqList;
    private Martix martix;
    private static final int MAX_WEIGHT=0x0000ffff;

    public MartixGraph() {
        this.seqList = new SeqList<E>();
        this.martix = new Martix();
    }

    public MartixGraph(E[] values){
        this();
        for (E value : values) {
            this.insert(value);
        }
    }

    public MartixGraph(E[] values,Triple[] edges){
        this(values);
        for (Triple edge : edges) {
            this.insert(edge);
        }
    }

    private void insert(Triple edge) {
        if (edge.getRow() != edge.getColumn()){
            if (edge.getValue() <= 0 || edge.getValue() >= MAX_WEIGHT){
                edge.setValue(MAX_WEIGHT);
            }
            this.martix.setValues(edge.getRow(),edge.getColumn(),edge.getValue());
        }else this.martix.setValues(edge.getRow(),edge.getColumn(),0);
    }

    @Override
    public String toString() {
        return "顶点数组" + this.seqList.toString() + "\n邻接矩阵" + this.martix.toString();
    }

    private int insert(E value) {
        this.seqList.insert(value);
        int size = this.seqList.size()-1;
        if (size >= this.martix.getRows()){
            this.martix.setRowsColumn(size+1,size+1);
        }
        for (int j=0;j < size;j++){
            this.martix.setValues(size,j,MAX_WEIGHT);
            this.martix.setValues(j,size,MAX_WEIGHT);
        }
        return size;
    }

    public void minSpanTree(){
        Triple[] mst = new Triple[seqList.size()];
    }
}
